import { get, request } from '../ajax'

import { getAjaxBaseUrl } from '../handler'

const controller = getAjaxBaseUrl(
  '/modelConfig',
  '/energy',
)

/** 添加应用模型配置 */
export function addModelConfig(data: {
  modelType: string
  pointId: number
  indicatorIds: (number | undefined)[]
}) {
  return withRequest(request)({
    url: `${controller}/addModelConfig`,
    method: 'post',
    params: {
      modelType: data.modelType,
      pointId: data.pointId,
      indicatorIds: data.indicatorIds.join(','),
    },
  })
}

/** 修改应用模型配置 */
export function updateModelConfig(data: {
  modelType: string
  pointId?: number
  indicatorIds: (number | undefined)[]
}) {
  return withRequest(request)({
    url: `${controller}/updateModelConfig`,
    method: 'post',
    params: {
      modelType: data.modelType,
      pointId: data.pointId || '',
      indicatorIds: data.indicatorIds.join(','),
    },
  })
}

/** 根据模型类别和点位获取配置信息 */
export function getMonitorConfig(modelType: string, pointId?: number | string) {
  return get(`${controller}/getMonitorConfig`, {
    modelType,
    pointId,
  })
}

/** 根据模型获取点位树形结构 */
export function getPointTreeByModel(modelType: string) {
  return get(`${controller}/getPointTreeByModel`, {
    modelType,
  })
}
